<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Your Article</title>
<link href="./css/bootstrap.min.css" rel="stylesheet">
<link href="./css/index.css" rel="stylesheet">
</head>
<body>
	<nav class="navbar navbar-fixed-top bg-primary">
       <div class="container">
           <div class="navbar-header">
               <a class="navbar-brand" href="#">
                   <img class="media-object headphoto" src="./upload/${currentUser.filename}" alt="headphoto" width="36px" height="36px">
               </a>
           </div>
           <h3>Welcome, ${currentUser.username} !</h3>
       </div>
    </nav>
    
    <div class="container box">
		
		<div class="panel panel-primary">
		  <!-- Default panel contents -->
		  <div class="panel-heading">Your Articles</div>
		
		  <!-- Table -->
		  <table class="table">
		  	<thead>
	          <tr>
	            <th>#</th>
	            <th>Title</th>
	            <th>Content</th>
	            <th>Autor</th>
	            <th>Date</th>
	            <th>Option</th>
	          </tr>
	        </thead>
	        <tbody>
	        	<c:forEach var="t" items="${articles}">
		          <tr>
		            <th scope="row">${t.id}</th>
		            <td>${t.title}</td>
		            <td>${t.content}</td>
		            <td>${t.username}</td>
		            <td>${t.publishDate}</td>
		            <td><a href="./del.do?id=${t.id}">Delete</a></td>
		          </tr>
		      </c:forEach>
	        </tbody>
		  </table>
		</div>
		
		<nav aria-label="Page navigation">
			<ul class="pagination">
			
				<li class="${currentPage == 0 ? 'disabled' : ''}"> 
				<c:if test="${currentPage == 0}">
					<a>
						<span>&laquo;</span>
					</a>
				</c:if>
				<c:if test="${currentPage != 0}">
					<a href="./list.do?page=${currentPage-1}">
						<span>&laquo;</span>
					</a>
				</c:if>
				</li>
				
				<c:if test="${currentPage < 7}">
					<c:forEach var="page" begin="0" end="${currentPage + 4}">
						<li class="${currentPage == page ? 'active' : ''}">
							<a href="./list.do?page=${page}">${page}</a>
						</li>
					</c:forEach>
					<li class="disabled"><a>...</a></li>
					<li><a href="./list.do?page=${total}">${total}</a></li>
				</c:if>
				
				<c:if test="${currentPage >= 7 && currentPage <= total-7}">
					<li><a href="./list.do?page=0">0</a></li> 
					<li class="disabled"><a>...</a></li>
					<c:forEach var="page" begin="${currentPage - 4}" end="${currentPage + 4}">
						<li class="${currentPage == page ? 'active' : ''}">
							<a href="./list.do?page=${page}">${page}</a>
						</li>
					</c:forEach>
					<li class="disabled"><a>...</a></li>
					<li><a href="./list.do?page=${total}">${total}</a></li>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
				</c:if>
				
				<c:if test="${currentPage > total-7}">
					<li class="disabled"><a>...</a></li>
					<c:forEach var="page" begin="${currentPage - 4}" end="${total}">
						<li class="${currentPage == page ? 'active' : ''}">
							<a href="./list.do?page=${page}">${page}</a>
						</li>
					</c:forEach>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
				</c:if>
				
				<li class="${currentPage == total ? 'disabled' : ''}">
					<c:if test="${currentPage == total}">
						<a>
							<span>&raquo;</span>
						</a>
					</c:if>
					<c:if test="${currentPage != total}">
						<a href="./list.do?page=${currentPage+1}">
							<span>&raquo;</span>
						</a>
					</c:if>
				</li>
				
			</ul>
		</nav>
		
		<footer class="footer">
        <p>&copy; 2017 favefan</p>
      </footer>
	</div>	
</body>
</html>